package example.avro.without_code_generation

import java.io.File

import org.apache.avro.Schema
import org.apache.avro.file.DataFileReader
import org.apache.avro.generic.{GenericDatumReader, GenericRecord}
import org.apache.avro.io.DatumReader

object DeserializingDemo extends App{
  val schema: Schema = new Schema.Parser().parse(getClass.getClassLoader.getResourceAsStream("user.avsc"))
  val datumReader :DatumReader[GenericRecord] = new GenericDatumReader[GenericRecord](schema)
  val file:File = new File("users_sample_without_generation.avro")
  val dataFileReader:DataFileReader[GenericRecord] = new DataFileReader[GenericRecord](file,datumReader)
  var user:GenericRecord = null
  while(dataFileReader.hasNext){
    user = dataFileReader.next(user)
    println(user)
  }
  dataFileReader.close()
}
